<?php
/**
 * Nadëb (Makú-Nadëb)
 * 
 * @author     Mateus Martins <mateusweb@gmail.com>
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 * @package    Nadeb
 * @version    1.0.0
 */


/**
 * Class Nadeb_Report_Filters_DateBetween
 * 
 * 
 * @category   Nadeb
 * @package    Nadeb_Report_Filters_DateBetween
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 */
abstract class Nadeb_Report_Filters_DateBetween
{
	public static function get_xhtml($_filtersConfigs)
	{
		/*
		 * adiciona o CSS do tema do UI no header
		 */
		$headers = Nadeb_Header::get_instance();
		$headers->new_css( '/public/admin/javascript/ui_theme/jquery-ui-1.8.2.custom.css' );
		
		$js = Nadeb_JScontroller::get_instance();
		$js->JSInstance = "admin_calendario";
		
		$sqlFilters = new Zend_Session_Namespace();
		$sqlFilters->dateBetweenColumn = $_filtersConfigs['column'];
		
		$gd  = $sqlFilters->queryDateBetween ? "\t\t\t<div class=\"dateTimeFilters selected\">\n" : "\t\t\t<div class=\"dateTimeFilters\">\n";
		$gd .= "\t\t\t\t<p class=\"fechar\"><a class=\"cancel_filters\" href=\"filterCancel/type/dateBetween\"> X </a></p>\n";
	    $gd .= "\t\t\t\t<p>\n";
		$gd .= "\t\t\t\t\tData de inicio: <input type=\"text\" id=\"start_date\" name=\"start_date\" value=\"{$sqlFilters->start_date}\"/>\n";
		$gd .= "\t\t\t\t</p>\n";
	    $gd .= "\t\t\t\t<p>\n";
		$gd .= "\t\t\t\t\tData de final: <input type=\"text\" id=\"end_date\" name=\"end_date\" value=\"{$sqlFilters->end_date}\"/>\n";
		$gd .= "\t\t\t\t</p>\n";
		$gd .= "\t\t\t</div>\n";
		
		return $gd;
	}
	
	public static function save_sql($_params)
	{
		$sqlFilters                   = new Zend_Session_Namespace();
		$sqlFilters->queryDateBetween = "(" . $sqlFilters->dateBetweenColumn . " BETWEEN '" . date("Y-m-d", strtotime($_params['start_date'])) . " 00:00:00' AND '" . date("Y-m-d", strtotime($_params['end_date'])) . " 23:59:59')";
		$sqlFilters->start_date       = $_params['start_date'];
		$sqlFilters->end_date         = $_params['end_date'];
	}
	
	public static function cancel_sql($_params)
	{
		$sqlFilters                    = new Zend_Session_Namespace();
		$sqlFilters->queryDateBetween  = null;
		$sqlFilters->start_date        = null;
		$sqlFilters->end_date          = null;
		$sqlFilters->dateBetweenColumn = null;
	}
	
	public static function get_sql()
	{
		$sqlFilters = new Zend_Session_Namespace();
		
		return $sqlFilters->queryDateBetween;
	}
}
